package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(20);not null;unique;comment:用户名"`
	Password string `gorm:"type:char(32);not null;comment:密码"`
	Mobile   string `gorm:"type:varchar(11);comment:手机号"`
	Avatar   string `gorm:"type:varchar(255);comment:头像"`
	Nickname string `gorm:"type:varchar(20);not null;comment:昵称"`
	Status   int    `gorm:"type:int;default:1;comment:状态:1正常 2禁用"`
}

func (u *User) Create() error {
	return DB.Create(&u).Error
}

// 根据用户名查找数据
func (u *User) FindByUsername(username string) error {
	return DB.Where("username = ?", username).Limit(1).Find(&u).Error
}
